﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Pong_Project.Game_objects
{
    class Bat : GameObjectMovable
    {
        public Bat(GameObjectIdentity identity, Vector2 position, Vector2 velocity, float speed)
            : base(identity, position, velocity, speed)
        {
            VelocityX = 0;
            VelocityY = 1;
            LayerDepth = 1.0f;
        }

        public void MoveDown()
        {
            if (VelocityY < 0)
            {
                if (Top > Speed * VelocityY + 1)
                    PositionY += Speed * VelocityY;
            }
            else if (Bottom < Game.WindowHeight - Speed * VelocityY)
            {
                PositionY += Speed * VelocityY;
            }
        }

        public void MoveUp()
        {
            if (VelocityY < 0)
            {
                if (Bottom < Game.WindowHeight - Speed * VelocityY)
                    PositionY -= Speed * VelocityY;
            }
            else if (Top > Speed * VelocityY + 1)
            {
                PositionY -= Speed * VelocityY;
            }
        }

        public override void Update(GameTime gameTime)
        {
            if (Identity == GameObjectIdentity.BatLeft)
            {
                if (Controls.MoveDownLeftBat)
                    MoveDown();
                if (Controls.MoveUpLeftBat)
                    MoveUp();
            }
            else if (Identity == GameObjectIdentity.BatRight)
            {
                if (Controls.MoveDownRightBat)
                    MoveDown();
                if (Controls.MoveUpRightBat)
                    MoveUp();
            }
            base.Update(gameTime);
        }

        public override void Reset()
        {
            if (Identity == GameObjectIdentity.BatLeft)
                PositionX = 0;
            else
                PositionX = Game.WindowWidth - Width;
            PositionY = Game.WindowHeight / 2 - Height / 2;
            VelocityX = 0;
            VelocityY = 1;
            ScaleX = 1.0f;
            ScaleY = 1.0f;
            Speed = 6.0f;
            Rotation = 0.0f;
            LayerDepth = 1.0f;
        }
    }
}
